
import gtk
import goocanvas


class Base(goocanvas.Group):

    def rgb(self,(r,g,b)):
        return "#%02x%02x%02x" % (r,g,b)

    def set_color(self):
        if self.name == "A" and self.downstream is False:
            return "#FAD2AB"
        elif self.name == "T" and self.downstream is False:
            return "#FAD2AB"
        elif self.name == "C" and self.downstream is False:
            return "#D2FAAB"
        elif self.name == "G" and self.downstream is False:
            return "#D2FAAB"
        elif self.name == "N" and self.downstream is False:
            return self.rgb((230,230,230))
        elif self.name == "A" and self.downstream is True:
            return "#967e66"
        elif self.name == "T" and self.downstream is True:
            return "#967e66"
        elif self.name == "C" and self.downstream is True:
            return "#93af77"
        elif self.name == "G" and self.downstream is True:
            return "#93af77"
        elif self.name == "N" and self.downstream is True:
            return self.rgb((230,230,230))

        else:
            return self.rgb((230,230,230))

    def __init__(self, canvas, nuc, motif,isdownstream):
        goocanvas.Group.__init__(self)

        self.hover_color=self.rgb((100,100,200))
        self.select_color=self.rgb((90,190,90))
        self.name = nuc[1].upper()
        self.downstream = isdownstream
        self.nuc_no = nuc[0]

        if not motif:
            self.normal_text_color=self.rgb((100,100,100))
            self.normal_color= self.set_color()
        else:
            self.normal_text_color=self.rgb((255,255,255))
            self.normal_color= self.rgb((172,36,48))
        #self.set_canvas(canvas)

        self.props.parent = canvas#.get_root_item()

        self.rect = goocanvas.Rect(parent=self, x=0, y=0, width=10, height=10, fill_color=self.normal_color , line_width=0)
        self.text = goocanvas.Text(parent=self, x=2, y=0, text=self.name, fill_color=self.normal_text_color, font="consolas")

        if self.nuc_no % 50 == 0 :
            self.indicator = goocanvas.Rect(parent=self, x=5,y=-10, width=1, height=4, fill_color="black" , line_width=0)
            self.text = goocanvas.Text(parent=self, x=5, y=-20, text=str(self.nuc_no + 1), fill_color=self.normal_text_color, font="consolas")



class Scheme(goocanvas.Group):

    def rgb(self,(r,g,b)):
        return "#%02x%02x%02x" % (r,g,b)

    def set_color(self):
        if self.name == "A" and self.downstream is False:
            return "#FAD2AB"
        elif self.name == "T" and self.downstream is False:
            return "#FAD2AB"
        elif self.name == "C" and self.downstream is False:
            return "#D2FAAB"
        elif self.name == "G" and self.downstream is False:
            return "#D2FAAB"
        elif self.name == "N" and self.downstream is False:
            return self.rgb((230,230,230))
        elif self.name == "A" and self.downstream is True:
            return "#967e66"
        elif self.name == "T" and self.downstream is True:
            return "#967e66"
        elif self.name == "C" and self.downstream is True:
            return "#93af77"
        elif self.name == "G" and self.downstream is True:
            return "#93af77"
        elif self.name == "N" and self.downstream is True:
            return self.rgb((230,230,230))
        else:
            return self.rgb((230,230,230))

    def __init__(self, canvas, nuc, motif, isdownstream):
        goocanvas.Group.__init__(self)

        self.hover_color=self.rgb((100,100,200))
        self.select_color=self.rgb((90,190,90))
        self.name = nuc
        self.downstream = isdownstream
        if not motif:
            self.normal_text_color=self.rgb((100,100,100))
            self.normal_color= self.set_color()
        else:
            self.normal_text_color=self.rgb((0,0,0))
            self.normal_color= "red"
        #self.set_canvas(canvas)
        self.props.parent = canvas#.get_root_item()
        self.rect = goocanvas.Rect(parent=self ,x=0,y=0, width=1, height=2, fill_color=self.normal_color , line_width=0)
        #self.text = goocanvas.Text(parent=self ,x=0,y=0, text =self.name, fill_color = self.normal_text_color, font="consolas")

